import { useEffect, useMemo, useState } from "react";
import { interval } from '@/utils/time.ts';
import { IGetMemoryAll } from '@/types/invoke-res-type.ts'
import { invoke } from '@tauri-apps/api/core';

export function useGetMemory() {
  const [memory, setMemory] = useState<IGetMemoryAll>();

  const getMemory = useMemo(() => {
    return interval(() => {
      invoke<IGetMemoryAll>("get_memory_all").then((data) => {
        setMemory(data);
      }).catch((err) => {
        console.error(err)
      })
    }, 2000, true);
  }, [])

  useEffect(() => {
    getMemory();
  }, [getMemory])

  return {
    memory,
  }
}